﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Wicresoft.SelfService.DAO;
using Wicresoft.SelfService.BL;
using Wicresoft.SelfService.BL.Interface;
using Wicresoft.SelfService.DAL;

namespace Wicresoft.SelfService.Portal.Controllers
{
    public class OSMaintainController : BaseController
    {
        private string ARServer;
        private string Mid_Base;
        private string appSystemName;
        public ITServiceHelper helper { get; private set; }
        public IUserSync userSync { get; private set; }
        public Wicresoft.SelfService.BL.Interface.IAppSystem myAppSystem { get; private set; }
        public static WFService.ApproveFlowClient IApproveFlow { get; private set; }
        protected override void Initialize(RequestContext requestContext)
        {
            if (helper == null) { helper = new ITServiceHelper(); }
            if (userSync == null) { userSync = new UserSync(); }
            if (myAppSystem == null) { myAppSystem = new MyAppSystem(); }
            if (IApproveFlow == null) { IApproveFlow = new WFService.ApproveFlowClient(); }

            ARServer = ConfigurationManager.AppSettings["ARServer"];
            Mid_Base = ConfigurationManager.AppSettings["ITSM_Mid_Tier"];//without end "/"
            appSystemName = ConfigurationManager.AppSettings["ApplicationSystemName"];
            if (string.IsNullOrEmpty(appSystemName)) appSystemName = "应用系统";
            base.Initialize(requestContext);
        }
        //
        // GET: /ServiceMaintain/

        [Authorize]
        public ActionResult Index()
        {
            List<OS> model = helper.getOSList();
            ViewData["OsList"] = model;
            return View();

        }

        [Authorize]
        public ActionResult ShowOS(int ID)
        {
            OS model = helper.getOSByID(ID);
            return PartialView(model);
        }

        [HttpPost]
        public ActionResult UpdateOS(OS model)
        {
            bool isOk = helper.updateOS(model);
            return Content(isOk ? "true" : "false");
        }



        [HttpPost]
        public ActionResult DeleteOS(OS model)
        {
            bool isOk = helper.deleteOS(model);
            return Content(isOk ? "true" : "false");
        }

        public ActionResult CreateOS()
        {
            return View();
        }

        [HttpPost]
        public ActionResult CreateOS(OS model)
        {
            bool isOk = helper.createOS(model);
            return Content(isOk ? "true" : "false");
        }

        [HttpPost]
        public ActionResult SearchByOSName(OS model)
        {
            bool flag = helper.searchByOSName(model);
            return Content(flag ? "true" : "false");

        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (this.helper != null)
                helper.Dispose();

            if (userSync != null && userSync is UserSync)
            {
                ((UserSync)userSync).Dispose();
            }
        }

    }
}
